package com.helwen.tools.zhijiang;

import org.apache.poi.xwpf.usermodel.*;
import org.junit.jupiter.api.Test;

import java.io.*;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


/**
 * 读取word，  只是读取国标中的word固定文件。  拼成将xml格式参数转成json参数，去调东软件平台将枝江数据上传到宜昌平台中。
 * 生成建表sql 与xml形式
 * @author Christmas_G
 *
 */
public class YiGongTiView {
    @Test
    public void readWordCreateSql() throws Exception {
        /*XWPFDocument document = new XWPFDocument(new FileInputStream("D:\\123\\全民健康\\检查报告\\2型糖尿病病例管理.docx"));
        Map<String,String> map2=getMap("D:\\123\\全民健康\\区域平台\\2型糖尿病专案登记.docx");*/
        /*XWPFDocument document = new XWPFDocument(new FileInputStream("D:\\123\\全民健康\\检查报告\\医保主表.docx"));
        Map<String,String> map2=getMap("D:\\123\\全民健康\\区域平台\\门(急)诊费用结算.docx");*/
        /*XWPFDocument document = new XWPFDocument(new FileInputStream("D:\\123\\全民健康\\检查报告\\医保主表.docx"));
        Map<String,String> map2=getMap("D:\\123\\全民健康\\区域平台\\住院费用结算.docx");*/
        /*XWPFDocument document = new XWPFDocument(new FileInputStream("D:\\123\\全民健康\\检查报告\\就诊信息.docx"));
        Map<String,String> map2=getMap("D:\\123\\全民健康\\区域平台\\门(急)诊诊断记录.docx");*/
        /*XWPFDocument document = new XWPFDocument(new FileInputStream("D:\\123\\全民健康\\检查报告\\就诊信息.docx"));
        Map<String,String> map2=getMap("D:\\123\\全民健康\\区域平台\\住院诊断记录.doc");*/

        /*XWPFDocument document = new XWPFDocument(new FileInputStream("D:\\123\\全民健康\\检查报告\\检查报告详情.docx"));
        Map<String,String> map2=getMap("D:\\123\\全民健康\\区域平台\\门(急)诊检查报告.doc");*/
        /*XWPFDocument document = new XWPFDocument(new FileInputStream("D:\\123\\全民健康\\检查报告\\检查报告详情.docx"));
        Map<String,String> map2=getMap("D:\\123\\全民健康\\区域平台\\住院检查报告.doc");*/
        /*XWPFDocument document = new XWPFDocument(new FileInputStream("D:\\123\\全民健康\\检查报告\\检查报告信息.docx"));
        Map<String,String> map2=getMap("D:\\123\\全民健康\\区域平台\\门(急)诊检查报告.doc");*/
        /*XWPFDocument document = new XWPFDocument(new FileInputStream("D:\\123\\全民健康\\检查报告\\检查报告信息.docx"));
        Map<String,String> map2=getMap("D:\\123\\全民健康\\区域平台\\住院检查报告.doc");*/
        /*XWPFDocument document = new XWPFDocument(new FileInputStream("D:\\123\\全民健康\\检查报告\\检验报告详情.docx"));
        Map<String,String> map2=getMap("D:\\123\\全民健康\\区域平台\\门(急)诊检验常规报告.docx");*/
        /*XWPFDocument document = new XWPFDocument(new FileInputStream("D:\\123\\全民健康\\检查报告\\检验报告详情.docx"));
        Map<String,String> map2=getMap("D:\\123\\全民健康\\区域平台\\住院检验常规报告.docx");*/
        XWPFDocument document = new XWPFDocument(new FileInputStream("D:\\123\\全民健康\\检查报告\\出院结算信息.docx"));
        Map<String,String> map2=getMap("D:\\123\\全民健康\\区域平台\\住院费用结算.docx");

       /* XWPFDocument document = new XWPFDocument(new FileInputStream("D:\\123\\全民健康\\检查报告\\2型糖尿病随访.docx"));
        Map<String,String> map2=getMap("D:\\123\\全民健康\\区域平台\\2型糖尿病随访记录.docx");*/
        /*XWPFDocument document = new XWPFDocument(new FileInputStream("D:\\123\\全民健康\\检查报告\\2型糖尿病用药.docx"));
        Map<String,String> map2=getMap("D:\\123\\全民健康\\区域平台\\2型糖尿病随访用药记录.docx");*/
        /*XWPFDocument document = new XWPFDocument(new FileInputStream("D:\\123\\全民健康\\检查报告\\个人基本信息.docx"));
        Map<String,String> map2=getMap("D:\\123\\全民健康\\区域平台\\个人健康档案基本健康状况.docx");*/

//        XWPFDocument document = new XWPFDocument(new FileInputStream("D:\\123\\全民健康\\检查报告\\高血压患者健康管理.docx"));
//        Map<String,String> map2=getMap("D:\\123\\全民健康\\区域平台\\高血压专案登记.docx");
        /*XWPFDocument document = new XWPFDocument(new FileInputStream("D:\\123\\全民健康\\检查报告\\高血压随访.docx"));
        Map<String,String> map2=getMap("D:\\123\\全民健康\\区域平台\\高血压随访记录.docx");*/
       /* XWPFDocument document = new XWPFDocument(new FileInputStream("D:\\123\\全民健康\\检查报告\\高血压用药.docx"));
        Map<String,String> map2=getMap("D:\\123\\全民健康\\区域平台\\高血压随访用药记录.docx");*/

        /*XWPFDocument document = new XWPFDocument(new FileInputStream("D:\\123\\全民健康\\检查报告\\老年人随访.docx"));
        Map<String,String> map2=getMap("D:\\123\\全民健康\\区域平台\\老年人随访记录.docx");*/
        /*XWPFDocument document = new XWPFDocument(new FileInputStream("D:\\123\\全民健康\\检查报告\\老年人随访用药.docx"));
        Map<String,String> map2=getMap("D:\\123\\全民健康\\区域平台\\老年人随访用药记录.docx");*/

        /*XWPFDocument document = new XWPFDocument(new FileInputStream("D:\\123\\全民健康\\检查报告\\严重精神障碍患者管理.docx"));
        Map<String,String> map2=getMap("D:\\123\\全民健康\\区域平台\\重性精神疾病专案登记.docx");*/
        /*XWPFDocument document = new XWPFDocument(new FileInputStream("D:\\123\\全民健康\\检查报告\\严重精神障碍患者随访.docx"));
        Map<String,String> map2=getMap("D:\\123\\全民健康\\区域平台\\重性精神疾病随访记录.docx");*/
//        XWPFDocument document = new XWPFDocument(new FileInputStream("D:\\123\\全民健康\\检查报告\\严重精神障碍患者用药.docx"));
//        Map<String,String> map2=getMap("D:\\123\\全民健康\\区域平台\\重性精神疾病随访用药记录.docx");
        //XWPFDocument document = new XWPFDocument(new FileInputStream("D:\\123\\全民健康\\检查报告\\老年人生活处理能力评估表.docx"));
        //XWPFDocument document = new XWPFDocument(new FileInputStream("D:\\123\\全民健康\\检查报告\\老年人中医药健康管理服务记录.docx"));
        //Map<String,String> map2=getMap("D:\\123\\全民健康\\区域平台\\老年人随访用药记录.docx");

        //XWPFDocument document = new XWPFDocument(new FileInputStream("D:\\123\\全民健康\\检查报告\\住院医嘱信息表.docx"));
        /*XWPFDocument document = new XWPFDocument(new FileInputStream("D:\\123\\全民健康\\检查报告\\住院医嘱明细信息.docx"));
        Map<String,String> map2=getMap("D:\\123\\全民健康\\区域平台\\住院医嘱记录.docx");*/
        /*XWPFDocument document = new XWPFDocument(new FileInputStream("D:\\123\\全民健康\\检查报告\\门诊就诊信息.docx"));
        Map<String,String> map2=getMap("D:\\123\\全民健康\\区域平台\\门急诊挂号登记.docx");*/

        /*XWPFDocument document = new XWPFDocument(new FileInputStream("D:\\123\\全民健康\\检查报告\\住院诊疗费用报告.docx"));
        Map<String,String> map2=getMap("D:\\123\\全民健康\\区域平台\\住院费用结算.docx");*/
        /*XWPFDocument document = new XWPFDocument(new FileInputStream("D:\\123\\全民健康\\检查报告\\门诊处方明细信息.docx"));
        Map<String,String> map2=getMap("D:\\123\\全民健康\\区域平台\\门(急)诊处方明细.docx");*/
        /*XWPFDocument document = new XWPFDocument(new FileInputStream("D:\\123\\全民健康\\检查报告\\住院收费明细信息.docx"));
        Map<String,String> map2=getMap("D:\\123\\全民健康\\区域平台\\住院费用结算明细.docx");*/
        /*XWPFDocument document = new XWPFDocument(new FileInputStream("D:\\123\\全民健康\\检查报告\\门诊收费明细信息.docx"));
        Map<String,String> map2=getMap("D:\\123\\全民健康\\区域平台\\门急诊费用结算明细.docx");*/
        /*XWPFDocument document = new XWPFDocument(new FileInputStream("D:\\123\\全民健康\\检查报告\\门诊收费信息.docx"));
        Map<String,String> map2=getMap("D:\\123\\全民健康\\区域平台\\门(急)诊费用结算.docx");*/
        /*XWPFDocument document = new XWPFDocument(new FileInputStream("D:\\123\\全民健康\\检查报告\\术后首次病程记录.docx"));
        Map<String,String> map2=getMap("D:\\123\\全民健康\\区域平台\\住院病程记录术后首次病程记录.doc");*/
        /*XWPFDocument document = new XWPFDocument(new FileInputStream("D:\\123\\全民健康\\检查报告\\首次病程记录.docx"));
        Map<String,String> map2=getMap("D:\\123\\全民健康\\区域平台\\住院病程记录首次病程记录.doc");*/
        /*XWPFDocument document = new XWPFDocument(new FileInputStream("D:\\123\\全民健康\\检查报告\\住院就诊记录信息.docx"));
        Map<String,String> map2=getMap("D:\\123\\全民健康\\区域平台\\住院入出院登记.docx");*/
        /*XWPFDocument document = new XWPFDocument(new FileInputStream("D:\\123\\全民健康\\检查报告\\术前讨论.docx"));
        Map<String,String> map2=getMap("D:\\123\\全民健康\\区域平台\\住院病程记录术前讨论.doc");*/
        /*XWPFDocument document = new XWPFDocument(new FileInputStream("D:\\123\\全民健康\\检查报告\\入院记录信息.docx"));
        Map<String,String> map2=getMap("D:\\123\\全民健康\\区域平台\\住院入院记录.doc");*/
        /*XWPFDocument document = new XWPFDocument(new FileInputStream("D:\\123\\全民健康\\检查报告\\上级医师查房记录.docx"));
        Map<String,String> map2=getMap("D:\\123\\全民健康\\区域平台\\住院病程记录上级医师查房记录.doc");*/
        /*XWPFDocument document = new XWPFDocument(new FileInputStream("D:\\123\\全民健康\\检查报告\\会诊记录.docx"));
        Map<String,String> map2=getMap("D:\\123\\全民健康\\区域平台\\住院会诊记录.doc");*/
        /*XWPFDocument document = new XWPFDocument(new FileInputStream("D:\\123\\全民健康\\检查报告\\日常病程记录.docx"));
        Map<String,String> map2=getMap("D:\\123\\全民健康\\区域平台\\住院病程记录日常病程记录.doc");*/
//        XWPFDocument document = new XWPFDocument(new FileInputStream("D:\\123\\全民健康\\检查报告\\出院小结.docx"));
//        Map<String,String> map2=getMap("D:\\123\\全民健康\\区域平台\\住院出院小结.doc");
        /*XWPFDocument document = new XWPFDocument(new FileInputStream("D:\\123\\全民健康\\检查报告\\出院记录信息.docx"));
        Map<String,String> map2=getMap("D:\\123\\全民健康\\区域平台\\住院出院记录.doc");*/

        try {
            // 获取word中的所有段落与表格
            List<IBodyElement> elements = document.getBodyElements();
            String protocol="";
            String[] arr={"tablename","table_name","tablename"};
            int i=0;
            for (IBodyElement element : elements) {
                // 段落
                if (element instanceof XWPFParagraph) {
                    String str= getTableCellText((XWPFParagraph) element);
                    if(str!=null && str.length()>1){
                        protocol=str;
                    }
                }
                // 表格
                else if (element instanceof XWPFTable) {
                    String explaintable="";
                    if(protocol!=null && !protocol.equals("")) {
                        if (protocol.indexOf("表名：") > 0) {
                            String[] farr = protocol.split("表名：");
                            protocol = farr[1];
                            explaintable = farr[0];
                        } else if (protocol.indexOf("表名:") > 0) {
                            String[] farr = protocol.split("表名:");
                            protocol = farr[1];
                            explaintable = farr[0];
                        } else if (protocol.indexOf("表:") > 0) {
                            String[] farr = protocol.split("表:");
                            protocol = farr[1];
                            explaintable = farr[0];
                        } else if (protocol.indexOf("表：") > 0) {
                            String[] farr = protocol.split("表：");
                            protocol = farr[1];
                            explaintable = farr[0];
                        } else if (protocol.indexOf("表") > 0) {
                            String[] farr = protocol.split("表");
                            protocol = farr[1];
                            explaintable = farr[0];
                        }
                    }
                    getTabelText((XWPFTable) element,explaintable,protocol,map2);
                    i++;
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            document.close();
        }
    }



    private String getTableCellText(XWPFParagraph paragraph) {
        // 获取段落中所有内容
        List<XWPFRun> runs = paragraph.getRuns();
        if (runs.size() == 0) {
            System.out.println("按了回车（新段落）");
            return "";
        }
        StringBuffer runText = new StringBuffer();
        for (XWPFRun run : runs) {
            runText.append(run.text());
        }
        //System.out.println(runText);

        return runText.toString();
    }

    /**
     * 获取表格内容
     *
     * @param table
     */
    private void getTabelText(XWPFTable table,String fileName,String protocol,Map<String,String> checkMp) throws Exception{
        List<XWPFTableRow> rows = table.getRows();
        protocol=getRealField(protocol);
        fileName=getRealField(fileName);
        File file=new File("D:\\123\\全民健康\\补充区域平台视图\\"+fileName+".txt");
        FileOutputStream fileOutputStream = new FileOutputStream(file);
        OutputStreamWriter osw = new OutputStreamWriter(fileOutputStream, "UTF-8");

        int x=0;
        StringBuffer ceateSql=new StringBuffer("create or replace view ").append(protocol).append(" as select ").append("--").append(fileName).append("\r\n");
        int index=0;
        int si=rows.size();
        for (XWPFTableRow row : rows) {
            index++;
            if(x==0){
                x++;
                continue;
            }
            List<XWPFTableCell> cells = row.getTableCells();
            if(cells.size()<3){
                x++;
                continue;
            }

            List<XWPFParagraph> ycpar = cells.get(2).getParagraphs();//取第3个单元格中的值
            String ycfield=getTableCellText(ycpar.get(0));//取注释


            //获取字段
            List<XWPFParagraph> paragraphs = cells.get(0).getParagraphs();//取第一个单元格中的值
            String path=getTableCellText(paragraphs.get(0));//字段值
            if(path==null || path.equals("")){
                continue;
            }
            else{
                if(checkMp.containsKey(ycfield)){
                    String nfield=checkMp.get(ycfield);
                    ceateSql.append(nfield+ " as "+path+",--").append(ycfield).append("\r\n");
                }else {
                    Map<String,String> copyMap=copyMap(checkMp);
                    //copyMap.putAll(checkMp);
                    Iterator<Map.Entry<String,String>> entries = copyMap.entrySet().iterator();
                    int isv=0;
                    while (entries.hasNext()) {
                        Map.Entry<String, String> entry = entries.next();
                        String key = entry.getKey();
                        if(key==null || key.equals("")){
                            continue;
                        }
                        String keym=getRealField(key);
                        String ycfieldm=getRealField(ycfield);
                        if(key.indexOf(ycfield)>-1){
                            isv=1;
                            ceateSql.append(entry.getValue()+ " as "+path+",--").append(ycfield).append("  ,对照过来:").append(key).append("\r\n");
                        }else if(ycfield.indexOf(key)>-1){
                            isv=1;
                            ceateSql.append(entry.getValue()+ " as "+path+",--").append(ycfield).append("  ,对照过来2:").append(key).append("\r\n");
                        }else if(path.equals("AuthorOrganization_Text") || ycfield.equals("医疗机构名称")){
                            if(key.indexOf("机构代码")>1){
                                isv=1;
                                ceateSql.append("(select d.org_name_s from HDI_HOSPITAL d where d.hos_code= ").append(entry.getValue()).append(") as "+path+",--医疗机构名称").append("  ,对照过来:").append(key).append("\r\n");
                            }
                        }else if(path.equals("AuthorOrganization") || ycfield.equals("医疗机构id")){
                            if(key.indexOf("机构代码")>1){
                                isv=1;
                                ceateSql.append("(select d.org_code_s from HDI_HOSPITAL d where d.hos_code= ").append(entry.getValue()).append(") as "+path+",--医疗机构id").append("  ,对照过来:").append(key).append("\r\n");
                            }
                        }else if(key.indexOf("身份证号码")>-1 || key.indexOf("身份证件号码")>-1){
                            if(ycfield.indexOf("身份证号码")>-1 || ycfield.indexOf("身份证件号码")>-1 || ycfield.indexOf("身份证号")>-1){
                                isv=1;
                                ceateSql.append(entry.getValue()+ " as "+path+",--").append(ycfield).append("\r\n");
                            }
                        }else if(keym.equals(ycfieldm)){
                                isv=1;
                                ceateSql.append(entry.getValue()+ " as "+path+",--").append(ycfield).append("\r\n");
                        }else if(key.indexOf("建档者姓名")>-1){
                            if(ycfield.indexOf("操作员姓名")>-1){
                                isv=1;
                                ceateSql.append(entry.getValue()+ " as "+path+",--").append(ycfield).append("\r\n");
                            }
                        }else if(key.indexOf("建档日期")>-1){
                            if(ycfield.indexOf("创建时间")>-1){
                                isv=1;
                                ceateSql.append(entry.getValue()+ " as "+path+",--").append(ycfield).append("\r\n");
                            }
                        }else if(key.indexOf("手术及操作")>-1){
                            if(ycfield.indexOf("手术")>-1 && ycfield.indexOf("手术及操作")==-1){
                                key=key.replace("手术及操作","手术");
                                if(key.equals(ycfieldm)){
                                    isv=1;
                                    ceateSql.append(entry.getValue()+ " as "+path+",--").append(ycfield).append("\r\n");
                                }

                            }
                        }else if(key.indexOf("专项档案编号")>-1){
                            if(ycfield.indexOf("业务流水号")>-1){
                                isv=1;
                                ceateSql.append(entry.getValue()+ " as "+path+",--").append(ycfield).append("\r\n");
                            }
                        }else if(key.indexOf("居民健康卡号")>-1 || key.indexOf("记录表单编号")>-1 || key.indexOf("随访编号")>-1){
                            if(ycfield.indexOf("记录id")>-1){
                                isv=1;
                                ceateSql.append(entry.getValue()+ " as "+path+",--").append(ycfield).append("\r\n");
                            }
                        }else if(key.indexOf("收缩压")>-1){
                            if(ycfield.indexOf("收缩压")>-1){
                                isv=1;
                                ceateSql.append(entry.getValue()+ " as "+path+",--").append(ycfield).append("\r\n");
                            }
                        }else if(key.indexOf("手术体位代码")>-1){
                            if(ycfield.indexOf("手术部位代码")>-1){
                                isv=1;
                                ceateSql.append(entry.getValue()+ " as "+path+",--").append(ycfield).append("\r\n");
                            }
                        }else if(key.indexOf("手术体位名称")>-1){
                            if(ycfield.indexOf("手术部位名称")>-1){
                                isv=1;
                                ceateSql.append(entry.getValue()+ " as "+path+",--").append(ycfield).append("\r\n");
                            }
                        }
                        else if(key.indexOf("舒张压")>-1){
                            if(ycfield.indexOf("舒张压")>-1){
                                isv=1;
                                ceateSql.append(entry.getValue()+ " as "+path+",--").append(ycfield).append("\r\n");
                            }
                        }else if(key.indexOf("户籍地址")>-1 || key.indexOf("户籍地址")>-1){
                            if(ycfield.indexOf("户籍地址")>-1 || ycfield.indexOf("户籍地址")>-1){
                                if(key.length()>6 && ycfield.length()>6){
                                    String s1=key.substring(0,6);
                                    String s2=ycfield.substring(0,6);
                                    if(s1.equals(s2)){
                                        isv=1;
                                        ceateSql.append(entry.getValue()+ " as "+path+",--").append(ycfield).append("\r\n");
                                    }else if(key.indexOf("邮政编码")>1 && ycfield.indexOf("邮政编码")>1){
                                        isv=1;
                                        ceateSql.append(entry.getValue()+ " as "+path+",--").append(ycfield).append("\r\n");
                                    }
                                }

                            }
                        }else if(key.indexOf("现住地址")>-1 || key.indexOf("现住地址")>-1){
                            if(ycfield.indexOf("现住地址")>-1 || ycfield.indexOf("现住地址")>-1){
                                if(key.length()>6 && ycfield.length()>6){
                                    String s1=key.substring(0,6);
                                    String s2=ycfield.substring(0,6);
                                    if(s1.equals(s2)){
                                        isv=1;
                                        ceateSql.append(entry.getValue()+ " as "+path+",--").append(ycfield).append("\r\n");
                                    }else if(key.indexOf("邮政编码")>1 && ycfield.indexOf("邮政编码")>1){
                                        isv=1;
                                        ceateSql.append(entry.getValue()+ " as "+path+",--").append(ycfield).append("\r\n");
                                    }
                                }

                            }
                        }
                    }
                    if(isv==1){

                    }else {
                        if(path.equals("AuthorOrganization_Text") || ycfield.equals("医疗机构名称")) {
                            ceateSql.append("(select d.org_name_s from HDI_HOSPITAL d where d.hos_code= "+path+") as "+path+",--医疗机构名称").append("\r\n");
                        }else if(path.equals("AuthorOrganization") || ycfield.equals("医疗机构id")){
                            ceateSql.append("(select d.org_code_s from HDI_HOSPITAL d where d.hos_code= "+path+") as "+path+",--医疗机构id").append("\r\n");
                        }
                        if(index==si){
                            ceateSql.append("'' as "+path+" --").append(ycfield).append("\r\n");
                        }else {
                            ceateSql.append("'' as "+path+",--").append(ycfield).append("\r\n");
                        }

                    }

                }
            }




        }
        String tablename=checkMp.get("new_table_name");

        ceateSql.append("from ").append(tablename).append(";");
        osw.write(ceateSql.toString()+"\r\n");

        osw.flush();
        osw.close();
        fileOutputStream.close();

    }


    private Map<String,String> getMap(String filePath) throws Exception{
        XWPFDocument document = new XWPFDocument(new FileInputStream(filePath));
        Map<String,String> map=new HashMap<>();
        try {
            // 获取word中的所有段落与表格
            List<IBodyElement> elements = document.getBodyElements();
            String protocol="";
            String[] arr={"tablename","table_name","tablename"};
            int i=0;
            for (IBodyElement element : elements) {
                // 段落
                if (element instanceof XWPFParagraph) {
                    String str= getTableCellText((XWPFParagraph) element);
                    if(str!=null && str.length()>1){
                        protocol=str;
                    }
                    if(protocol!=null && !protocol.equals("")){
                        if(protocol.indexOf("表名：")>0){
                            String[] farr=protocol.split("表名：");
                            protocol=farr[1];
                        }else if(protocol.indexOf("表名:")>0){
                            String[] farr=protocol.split("表名:");
                            protocol=farr[1];
                        }else if(protocol.indexOf("表:")>0){
                            String[] farr=protocol.split("表:");
                            protocol=farr[1];
                        }else if(protocol.indexOf("表：")>0){
                            String[] farr=protocol.split("表：");
                            protocol=farr[1];
                        }else if(protocol.indexOf("表")>0){
                            String[] farr=protocol.split("表");
                            protocol=farr[1];
                        }
                    }

                }
                // 表格
                else if (element instanceof XWPFTable) {
                    Map<String,String> data=getTabelMapText((XWPFTable) element,arr[i]);
                    if(!data.isEmpty()){
                        map=data;
                        map.put("new_table_name",getRealField(protocol));
                        i++;
                    }

                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            document.close();
        }
        return map;
    }

    //去掉特殊字符
    private String getRealField(String str){
        if(str==null|| str.equals("")){
            return str;
        }
        String regEx="[`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~！@#￥%……&*（）——+|{}【】‘；：”“’。，、？]";
        Pattern p = Pattern.compile(regEx);
        Matcher m = p.matcher(str);
        String s =m.replaceAll("").trim();
        return s;
    }

    private Map<String,String> copyMap(Map<String,String> map){

        Iterator<Map.Entry<String,String>> entries = map.entrySet().iterator();
        Map<String,String> remap=new HashMap<>();
        while (entries.hasNext()) {
            Map.Entry<String, String> entry = entries.next();
            String key = entry.getKey();
            remap.put(key,entry.getValue());
        }
        return remap;
    }
    /**
     * 获取表格内容
     *
     * @param table
     */
    private Map<String,String> getTabelMapText(XWPFTable table,String protocol) throws Exception{
        List<XWPFTableRow> rows = table.getRows();
        int x=0;
        StringBuffer ceateSql=new StringBuffer("create table HIIP.tablename(");
        StringBuffer commonSql=new StringBuffer("");
        StringBuffer xmlStr=new StringBuffer("");
        StringBuffer jsonStr=new StringBuffer("");
        Map<String,String> checkMp=new HashMap<>();
        int jj=1;
        for (XWPFTableRow row : rows) {
            if(x==0){
                x++;
                List<XWPFTableCell> cells = row.getTableCells();
                if(cells.size()<5){
                    break;
                }

                List<XWPFParagraph> ycpar1 = cells.get(2).getParagraphs();//取第3个单元格中的值
                String ycfield1=getTableCellText(ycpar1.get(0));//
                if(ycfield1.equals("字段描述")|| ycfield1.equals("数据元名称") || ycfield1.equals("字段名称")){
                    jj=2;
                }
                List<XWPFParagraph> ycpar2 = cells.get(3).getParagraphs();//取第4个单元格中的值
                String ycfield2=getTableCellText(ycpar2.get(0));//
                if(ycfield2.equals("字段描述")|| ycfield2.equals("数据元名称") || ycfield2.equals("字段名称")){
                    jj=3;
                }
                continue;
            }
            List<XWPFTableCell> cells = row.getTableCells();
            if(cells.size()<6){
                break;
            }
            List<XWPFParagraph> ycpar = cells.get(jj).getParagraphs();//取第2个单元格中的值
            String ycfield=getTableCellText(ycpar.get(0));//

            //获取字段
            List<XWPFParagraph> paragraphs = cells.get(0).getParagraphs();//取第一个单元格中的值
            String path=getTableCellText(paragraphs.get(0));//
            if(ycfield!=null && !ycfield.equals("")){
                checkMp.put(ycfield,path);
            }


        }

        return checkMp;
    }

    private String getSpecificationWord(String word){
        if(word.length()>1){
            return word.substring(0, 1).toUpperCase()+word.substring(1);
        }else {
            return word;
        }
    }
}
